#include "GMSyncPos.h"
#include "TimerMS.h"
#include "ClientManager.h"
#include "ClientPlayerManager.h"

#include <D3DX10.h>

GMSyncPos::GMSyncPos()
{
	m_id = 0;
	m_posX = 0;
	m_posY = 0;
	m_posZ = 0;
}

void GMSyncPos::Execute()
{
	TheCPManager::Instance()->SetClientPos(m_id, Vec3fNet(m_posX, m_posY, m_posZ));
}

bool GMSyncPos::Read(SocketMessage* sm)
{
	int tempTS = 0;
	sm->ReadInt(&tempTS);
	m_timeStamp = (unsigned int)tempTS;

	sm->ReadInt(&m_id);
	sm->ReadFloat(&m_posX);
	sm->ReadFloat(&m_posY);
	sm->ReadFloat(&m_posZ);

	return true;
}

void GMSyncPos::Write(SocketMessage* sm)
{
	sm->WriteString("GMSyncPos");

	m_timeStamp = TheTimerMS::Instance()->GetTimeMS();

	sm->WriteInt(m_timeStamp);
	sm->WriteInt(m_id);
	sm->WriteFloat(m_posX);
	sm->WriteFloat(m_posY);
	sm->WriteFloat(m_posZ);
}

void GMSyncPos::SetID(int id)
{
	m_id = id;
}

int GMSyncPos::GetID() const
{
	return m_id;
}

Vec3fNet GMSyncPos::GetPos() const
{
	return Vec3fNet(m_posX, m_posY, m_posZ);
}

void GMSyncPos::SetPos(const Vec3fNet& pos)
{
	m_posX = pos.x;
	m_posY = pos.y;
	m_posZ = pos.z;
}